# MT::Plugin::DialAnchor
# Author: Takashi Ishikawa (http://www.ana-kutsu.com/)
# Copyright (C) 2011, Takashi Ishikawa.
#
# This program is distributed under the terms of the
# GNU General Public License, version 2.


package MT::Plugin::DialAnchor;
use strict;

use base qw( MT::Plugin );
use MT::Template::Context;
use MT::Sanitize;
use MT::Log;

my $plugin = new MT::Plugin::DialAnchor({
    name => 'DialAnchor',
    version => '1.0',
    description => 'Adding a html anchor to call over the phone number like string.',
    doc_link => 'http://code.google.com/p/mt-plugin-dial-anchor/wiki/InstallationAndUsage',
    author_name => "Takashi Ishikawa",
    author_link => "http://www.ana-kutsu.com/"
});
MT->add_plugin($plugin);

MT::Template::Context->add_global_filter('dial_anchor' => \&dial_anchor);

sub dial_anchor {
	my ($strContent, $strArg, $objContxt) = @_;
	
	if ($strArg) {
		$strContent =~ s/(\d{10,11})/<a href="tel:$1">$1<\/a>/g;
		$strContent =~ s/(\d{2,5})\-(\d{1,4})\-(\d{3,4})/<a href="tel:$1$2$3">$1-$2-$3<\/a>/g;
	}
	
	return $strContent;
};

1;
